#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define pip pair<int , pair<int , int> >
#define pi pair<int , int>
#define TASKNAME "demcap"

using namespace std;

const int N = 1e6+7 , M = 1e8 , MOD = 2023 , oo = 1e9+7;

int j , i , n , k;
bool check[N];

void Build()
{
	for (i=2 ; i*i <= N ; i++)
		if (!check[i])
			for (j=i*i ; j<=N ; j+=i)
				check[j] = true;
}

signed main() {
	if (fopen(TASKNAME".inp" , "r"))
		{
			freopen(TASKNAME".inp" , "r" , stdin);
			freopen(TASKNAME".out" , "w" , stdout);
		}
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	Build();
	cin >> n >> k;
	int res = 0;
	for (i=k+2 ; i<=n ; i++)
		res += (!check[i]) * (!check[i-k]);
	cout << res;
	return 0;
}
